package com.itheima.个人代码.IO流2;

import java.io.*;

public class Demo13 {

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //objectOutputStream();
        objectInputStream();

    }

    private static void objectInputStream() throws IOException, ClassNotFoundException {
        //1.创建对象反序列化流
        ObjectInputStream ois=new ObjectInputStream(new FileInputStream
                ("IO流2和对象操作流properties\\stu3.txt"));
        //2.通过反序列化流读取数据到内存中,并转化成对象
        Studentt stu =(Studentt) ois.readObject();
        System.out.println(stu);
        ois.close();//3.关闭流


    }

    public static void objectOutputStream() throws IOException {
        //1.将对象实现序列化接口, 2.创建对象序列化流
        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream
                ("IO流2和对象操作流properties\\stu3.txt"));
        //3.序列化流将对象写入到文件中
        oos.writeObject(new Studentt("zhangsan",22,'男'));
        //关闭序列化流
        oos.close();
    }
}








class Studentt implements Serializable{
    private String name;
    private int age;
    private char sex;

    public Studentt() {
    }

    public Studentt(String name, int age, char sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    @Override
    public String toString() {
        return "姓名: " + this.name + "   年龄: " + this.age + "    性别: " + this.sex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public char getSex() {
        return sex;
    }

    public void setSex(char sex) {
        this.sex = sex;
    }


}